package org.iiitb.assignment.wizards;

import java.util.Calendar;

import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.DateTime;

public class WScreenThree extends WizardPage {
  private List travelAgent;
  private DateTime travelDate;
  private Composite container;

  public WScreenThree() {
    super("Third Page");
    setTitle("Select your agent and date of travel.");
    setDescription("You need to select your agent and date of travel here.");
  }

  @Override
  public void createControl(Composite parent) {
    container = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout();
    container.setLayout(layout);
    layout.numColumns = 2;
    Label label1 = new Label(container, SWT.NULL);
    label1.setText("Select Agent Name : ");

    travelAgent = new List(container, SWT.BORDER);
    travelAgent.add("KPN Travels");
    travelAgent.add("SRS Travels");
    travelAgent.addSelectionListener(new SelectionListener() {
		
		@Override
		public void widgetSelected(SelectionEvent e) {
			// TODO Auto-generated method stub
			if(travelAgent.getSelectionCount()==1){
				setPageComplete(true);
			}else{
				setPageComplete(false);
			}
			
		}
		
		@Override
		public void widgetDefaultSelected(SelectionEvent e) {
			// TODO Auto-generated method stub
			
		}
	});    
	
    
    Label l2 = new Label(container,SWT.NONE);
    l2.setText("Select Travel Start date : ");
    
    Calendar now  = Calendar.getInstance();
    travelDate = new DateTime(container, SWT.DATE|SWT.BORDER|SWT.DROP_DOWN);
    travelDate.setDate(now.get(Calendar.YEAR),now.get(Calendar.MONTH) ,now.get(Calendar.DATE));
    travelDate.addKeyListener(new KeyListener() {
		
		@Override
		public void keyReleased(KeyEvent e) {
			// TODO Auto-generated method stub
			
		}
		
		@Override
		public void keyPressed(KeyEvent e) {
			// TODO Auto-generated method stub
			
		}
	});
    
    // Required to avoid an error in the system  
    setControl(container);
    setPageComplete(false);

  }

  public String getTravelAgent() {
    return travelAgent.getSelection()[0];
  }

public Calendar getTravelDate() {
	// TODO Auto-generated method stub
	Calendar c = Calendar.getInstance();
	c.set(travelDate.getYear(), travelDate.getMonth(), travelDate.getDay(),0,0,0);
	return c;
}
} 